<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/23
 * Time: 13:33
 */
include_once 'class/Http.php';
$config= include('class/config.php');

//$redis = new \think\cache\driver\Redis($config['redis']);
//$db = new \think\Db($config['db']);
$http = new Http();
$genderList=[1,2];
$baseUrl="47.56.207.234/v3/find/more?classifyId=";

//2ES2FkaP&page=1
$cateList = file_get_contents('data/catelist.csv');
$cateList = array_filter(explode("\r",$cateList));

foreach ($cateList as $cate){
    $cate = json_decode($cate,true);
    $page=1;
    $page = getBooks($cate['cId'],$page);
}

function getBooks($cId,$page){
    $http = new Http();
    $genderList=[1,2];
    $baseUrl="47.56.207.234/v3/find/more?classifyId=";
    $url = $baseUrl.$cId."&page=".$page;
    $list = $http::curlPost($url);
    $list = json_decode($list,true);
    if($list['status'] == 0 && !empty($list['data']['ns'])){
        $dataList = $list['data']['ns'];
        foreach ($dataList as $book){
            file_put_contents("data/bookList.csv",json_encode($book,258).PHP_EOL,FILE_APPEND);
        }
    }
    if($list['data']['more'] == true){
         ++ $page;
         getBooks($cId,$page);
    }
    return false;
}


